// Ofri Keidar 302933981 group 05package operator;
package operator;

import model.ApartmentsManager;
import model.Model;
import model.database.ApartmentsDB;
import model.database.DBException;
import model.database.Database;
import controller.Controller;
import controller.Transactor;
import view.View;
import view.UserInterface;

/**
 * This class holds main function, where system is initialized and then starts running 
 */
public class OperateSystem {

	private View sysManager;
	
	/**
	 * Allocates an object to operate the system.
	 * Uses the object to initialize the system and
	 * then to start system's running 
	 * @param args- none
	 */
	public static void main(String[] args) {
		
		// allocate a new operator for the system
		OperateSystem operator;
		try {
			operator = new OperateSystem();
			operator.start(); // run system		
		} catch (DBException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Creates a new OperateSystem instance
	 * @throws DBException 
	 */
	public OperateSystem() throws DBException {
		// create a new database
		Database database = new ApartmentsDB();

		// create a new model
		Model model = new ApartmentsManager(database);

		// create a controller
		Controller controller = new Transactor(model);

		// create an object to manage system
		sysManager = new UserInterface(controller);
	}
	
	/**
	 * Starts system's running using the system manager object
	 */
	private void start() {
		
		// start system's running
		sysManager.startRunning();
	}
}